﻿# CMakeList.txt : CMake project for BaseTool, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)

project(TyzApp)

# Set file's encoding
#add_compile_options("$<$<C_COMPILER_ID:MSVC>:/source-charset:utf-8>")

#add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")

add_definitions(-DUNICODE -D_UNICODE)

# Common section
SET(PROJECT_APP_DIR "./App")

SET(PROJECT_TOOL_DIR "./BaseTool")

SET(PROJECT_EXTRA_TOOL_DIR "./ExtraTool")

SET(PROJECT_TOOLTEST_DIR "./ToolTest")

SET(SHARE_LIB_DIR "../ShareLib")

##################################BaseTool###########################################
# Add third party include
SET(BOOST_HEAD_DIR ${SHARE_LIB_DIR}/Boost)

include_directories(${PROJECT_APP_DIR} 
${PROJECT_TOOL_DIR} 
${PROJECT_EXTRA_TOOL_DIR} 
${PROJECT_TOOLTEST_DIR} 
${BOOST_HEAD_DIR} )

# Add third party lib's directory
SET(BOOST_LIB_DIR ${BOOST_HEAD_DIR}/stage/lib)

IF(CMAKE_BUILD_TYPE STREQUAL Debug)
	IF(CMAKE_CL_64)
	link_directories(${BOOST_LIB_DIR}/x64/Debug)
	ELSE()
	link_directories(${BOOST_LIB_DIR}/x86/Debug)
	ENDIF()
ENDIF()

IF(CMAKE_BUILD_TYPE STREQUAL Release)
	IF(CMAKE_CL_64)
	link_directories(${BOOST_LIB_DIR}/x64/Release)
	ELSE()
	link_directories(${BOOST_LIB_DIR}/x86/Release)
	ENDIF()
ENDIF()

# Add src files
FILE(GLOB_RECURSE ALL_BASE_TOOL ${PROJECT_TOOL_DIR}/BSException/*.h 
${PROJECT_TOOL_DIR}/BSException/*.cpp 
${PROJECT_TOOL_DIR}/Buffer/*.h 
${PROJECT_TOOL_DIR}/Buffer/*.cpp 
${PROJECT_TOOL_DIR}/Common/*.h 
${PROJECT_TOOL_DIR}/Common/*.cpp 
${PROJECT_TOOL_DIR}/DateTime/*.h 
${PROJECT_TOOL_DIR}/DateTime/*.cpp 
${PROJECT_TOOL_DIR}/Directory/*.h 
${PROJECT_TOOL_DIR}/Directory/*.cpp 
${PROJECT_TOOL_DIR}/DllLoader/*.h 
${PROJECT_TOOL_DIR}/DllLoader/*.cpp 
${PROJECT_TOOL_DIR}/Encoding/*.h 
${PROJECT_TOOL_DIR}/Encoding/*.cpp 
${PROJECT_TOOL_DIR}/EventBase/*.h 
${PROJECT_TOOL_DIR}/EventBase/*.cpp 
${PROJECT_TOOL_DIR}/EventHandler/*.h 
${PROJECT_TOOL_DIR}/EventHandler/*.cpp 
${PROJECT_TOOL_DIR}/File/*.h 
${PROJECT_TOOL_DIR}/File/*.cpp 
${PROJECT_TOOL_DIR}/ini/*.h 
${PROJECT_TOOL_DIR}/ini/*.cpp 
${PROJECT_TOOL_DIR}/Json/*.h 
${PROJECT_TOOL_DIR}/Json/*.cpp 
${PROJECT_TOOL_DIR}/Log/*.h 
${PROJECT_TOOL_DIR}/Log/*.cpp 
${PROJECT_TOOL_DIR}/ModuleLoader/*.h 
${PROJECT_TOOL_DIR}/ModuleLoader/*.cpp 
${PROJECT_TOOL_DIR}/Uuid/*.h 
${PROJECT_TOOL_DIR}/Uuid/*.cpp)

# Make base tool to be static library
add_library(TyzBaseTool STATIC ${ALL_BASE_TOOL})

####################################LibCurl########################################
# ExtraTool
# Add third party include
SET(CURL_HEAD_DIR ${SHARE_LIB_DIR}/LibCurl/include)

include_directories(${CURL_HEAD_DIR})

# Add third party lib's directory
SET(CURL_LIB_DIR ${SHARE_LIB_DIR}/LibCurl/lib)

IF(CMAKE_BUILD_TYPE STREQUAL Debug)
	IF(CMAKE_CL_64)
	link_directories(${CURL_LIB_DIR}/x64/Debug)
	ELSE()
	link_directories(${CURL_LIB_DIR}/x86/Debug)
	ENDIF()
ENDIF()

IF(CMAKE_BUILD_TYPE STREQUAL Release)
	IF(CMAKE_CL_64)
	link_directories(${CURL_LIB_DIR}/x64/Release)
	ELSE()
	link_directories(${CURL_LIB_DIR}/x86/Release)
	ENDIF()
ENDIF()

# Add src files
FILE(GLOB_RECURSE ALL_EXTRA_TOOL ${PROJECT_EXTRA_TOOL_DIR}/*.h  ${PROJECT_EXTRA_TOOL_DIR}/*.cpp)

# Link base tool
add_library(TyzLibCurl SHARED ${ALL_EXTRA_TOOL})

# Link base tool
IF(CMAKE_BUILD_TYPE STREQUAL Debug)
	target_link_libraries(TyzLibCurl TyzBaseTool libcurl_debug)
ENDIF()

IF(CMAKE_BUILD_TYPE STREQUAL Release)
	target_link_libraries(TyzLibCurl TyzBaseTool libcurl)
ENDIF()

###################################ToolTest#######################################
# Tool Test
FILE(GLOB_RECURSE ALL_TOOL_TEST ${PROJECT_TOOLTEST_DIR}/*.h  ${PROJECT_TOOLTEST_DIR}/*.cpp)

# Make tool test to be an exe application
add_executable(TyzToolTest ${ALL_TOOL_TEST})

# Link base tool
target_link_libraries(TyzToolTest TyzBaseTool TyzLibCurl)

###################################App############################################
# Add third party include
SET(FFMPEG_HEAD_DIR ${SHARE_LIB_DIR}/FFmpeg/include)

include_directories(${FFMPEG_HEAD_DIR})

# Add third party lib's directory
SET(FFMPEG_LIB_DIR ${SHARE_LIB_DIR}/FFmpeg/lib)

IF(CMAKE_BUILD_TYPE STREQUAL Debug)
	IF(CMAKE_CL_64)
	link_directories(${FFMPEG_LIB_DIR}/x64/Debug)
	ELSE()
	link_directories(${FFMPEG_LIB_DIR}/x86/Debug)
	ENDIF()
ENDIF()

IF(CMAKE_BUILD_TYPE STREQUAL Release)
	IF(CMAKE_CL_64)
	link_directories(${FFMPEG_LIB_DIR}/x64/Release)
	ELSE()
	link_directories(${FFMPEG_LIB_DIR}/x86/Release)
	ENDIF()
ENDIF()

# Add source to this project
FILE(GLOB_RECURSE APP ${PROJECT_APP_DIR}/*.h  ${PROJECT_APP_DIR}/*.cpp)

# Make tool test to be an exe application
#add_executable(TyzApp ${APP})

add_library(TyzApp SHARED ${APP})

# Link base tool
target_link_libraries(TyzApp libavcodec 
	libavdevice 
	libavfilter 
	libavformat 
	libavutil 
	libpostproc 
	libswresample 
	libswscale)
